<template>
    <div>
        <target-edit controlType="city" :editFormData="editFormData" @success="success" @reject="reject" v-if="load"></target-edit>
    </div>
</template>

<script>
import TargetEdit from '@/template/target-edit/index.vue'
export default {
	components: {TargetEdit},
	data() {
		return {
            editFormData: {},
            load: false
		};
	},
    computed: {
        documentClientHeight: {
            get () { return this.$store.state.common.documentClientHeight }
        },
        menuActiveName: {
            get () { return this.$store.state.common.menuActiveName },
            set (val) { this.$store.commit('common/updateMenuActiveName', val) }
        },
        mainTabs: {
            get () { return this.$store.state.common.mainTabs },
            set (val) { this.$store.commit('common/updateMainTabs', val) }
        },
        mainTabsActiveName: {
            get () { return this.$store.state.common.mainTabsActiveName },
            set (val) { this.$store.commit('common/updateMainTabsActiveName', val) }
        },
    },
    mounted () {
        this.getFormDataFromId();
    },
    methods: {
        getFormDataFromId(){
            if(wfy.empty(wfy.getPara("id"))){
                this.removeTabHandle(this.mainTabsActiveName)
                this.$router.push({
                    path: 'audit-review',
                    query: {  }
                })
            }
            try {
                this.editFormData =  JSON.parse(sessionStorage.cityInitFormData);
                console.log('🚀 ~ this.editFormData', this.editFormData)
                this.$nextTick(() => {
                    this.load = true;
                })
            }catch (e) {

            }
        },
        // tabs, 删除tab
        removeTabHandle (tabName) {
            this.mainTabs = this.mainTabs.filter(item => item.name !== tabName)
            if (this.mainTabs.length >= 1) {
                // 当前选中tab被删除
                if (tabName === this.mainTabsActiveName) {
                    this.$router.push({ name: this.mainTabs[this.mainTabs.length - 1].name }, () => {
                        this.mainTabsActiveName = this.$route.name
                    })
                }
            } else {
                this.menuActiveName = ''
                this.$router.push({ name: 'home' })
            }
        },
        reject(){
            this.$alert("已驳回！","友情提醒",{
                callback: () => {
                    this.removeTabHandle(this.mainTabsActiveName)
                    this.$router.push({
                        path: 'audit-review',
                        query: { evalYear : message.evalYear  }
                    })
                }
            })
        },
        success(message){
          console.info("return message"+message)
            this.$alert("审批成功！","友情提醒",{
                callback: () => {
                    this.removeTabHandle(this.mainTabsActiveName)
                    this.$router.push({
                        path: 'audit-review',
                        query: { reginId : message.reginId, evalYear : message.evalYear }
                    })
                }
            })
        }
    }
}
</script>

<style lang="scss" scoped>

</style>
